﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using GenericValidation.Resources;

namespace GenericValidation
{
    /// <summary>
    /// Handles domain model validation by resolving the Validation classes.
    /// Possible implementation of this interface may load validations from Assemblies, IoC containers, or any other suitable containers.
    /// </summary>
    public interface IValidationManager
    {
        IValidationFactory Factory { get; set; }
        ValidationResult Validate(object item, params string[] tags);
    }
    
    /// <summary>
    /// Handles domain model validation by resolving the Validation classes.
    /// </summary>
    public class ValidationManager : IValidationManager
    {
        public IValidationFactory Factory { get; set; }

        public ValidationManager(IValidationFactory factory)
        {
            this.Factory = factory;
        }

        public ValidationResult Validate(object item, params string[] tags)
        {
            var validation = Factory.Resolve(item.GetType());
            return validation.Validate(item, tags);
        }

        public IValidation ResolveItem<T>() where T:class
        {
            var theResult = Factory.Resolve<T>();
            return theResult;
        }
    }
}
